<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="author" content="">
    <title></title>
    <style>
       h1{
           text-align: center;
           margin-top: 80px;
       }
    </style>
</head>

<body>
    <h1>发布时间：<span></span></h1>

    <script>
        var nowTime = new Date();
        var endTime = new Date('2021-5-5 13:20:00');
        var num = (nowTime.getTime() - endTime.getTime()) / 1000;

        var day = parseInt(num / (24 * 60 * 60));
        num = num % (24 * 60 * 60);
        var hour = parseInt(num / (60 * 60));
        num = num % (60 * 60);
        var min = parseInt(num / (60));

        var span = document.querySelector('span');
        if (min < 1) {
            span.innerHTML = '刚刚发布';
        } else if (hour < 1) {
            span.innerHTML = min + '分钟前';
        } else if (day < 1) {
            span.innerHTML = hour + '小时前';
        } else {
            span.innerHTML = day + '天前';
        }

    </script>
</body>

</html>